﻿using System;
using System.Drawing;

namespace idea0
{
    public class Class1_child
    {
        public int[,] WhiteBoard = new int[13, 25];
        private Class1 blackWalls;
        public string[,] PowerUpTypes; // 存储道具类型

        public Class1_child(Class1 blackWalls)
        {
            this.blackWalls = blackWalls;
            InitializeWhiteBoard();
            HideWhiteBehindBlack();
        }

        public void InitializeWhiteBoard()
        {
            WhiteBoard = new int[13, 25];
            PowerUpTypes = new string[13, 25];
        }

        public void HideWhiteBehindBlack()
        {
            Random rand = new Random();
            int totalBlackCells = blackWalls.CountBlackCells();
            int whiteCellsNeeded = totalBlackCells / 3;

            int count = 0;
            string[] powerUpTypes = { "lifeplus", "bombplus" }; // 只生成两种道具
            while (count < whiteCellsNeeded)
            {
                int x = rand.Next(0, 25);
                int y = rand.Next(0, 13);
                if (blackWalls.Board[y, x] == 1 && WhiteBoard[y, x] == 0)
                {
                    WhiteBoard[y, x] = 1;
                    PowerUpTypes[y, x] = powerUpTypes[rand.Next(2)]; // 随机生成两种道具
                    count++;
                }
            }
        }

        public bool IsWhiteCell(int x, int y)
        {
            return WhiteBoard[y, x] == 1;
        }

        public string GetPowerUpType(int x, int y)
        {
            return PowerUpTypes[y, x];
        }

        public void Draw(Graphics g, int cellSize)
        {
            for (int i = 0; i < 13; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    if (WhiteBoard[i, j] == 1)
                    {
                        string imagePath = Path.Combine(Application.StartupPath, "gif", PowerUpTypes[i, j] + ".png");
                        Image powerUpImage = Image.FromFile(imagePath);
                        int x = j * cellSize + cellSize / 3 - powerUpImage.Width / 3;
                        int y = i * cellSize + cellSize / 3 - powerUpImage.Height / 3;
                        g.DrawImage(powerUpImage, x, y);
                    }
                }
            }
        }
    }
}